package cn.bytepulse.web.video.controller;

import cn.bytepulse.annotation.Log;
import cn.bytepulse.pojo.AjaxResult;
import cn.bytepulse.web.video.entity.VideoParts;
import cn.bytepulse.web.video.entity.Videos;
import cn.bytepulse.web.video.service.VideoService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

/**
 * @author jiejiebiezheyang
 * @since 2025-03-17 13:00
 */
@Tag(name = "视频管理")
@RequestMapping("/video")
@RestController
@RequiredArgsConstructor
public class VideoController {

    private final VideoService videoService;

    @GetMapping("/list")
    @Operation(summary = "视频列表")
    @Log(value = "视频管理-视频列表", persist = true)
    public AjaxResult list(@RequestParam(required = false) String keyword) {
        return videoService.list(keyword);
    }

    @PostMapping("/add")
    @Operation(summary = "新增视频")
    @Log(value = "视频管理-新增视频", persist = true)
    public AjaxResult add(@RequestBody Videos videos) {
        return videoService.add(videos);
    }

    @DeleteMapping("/delete")
    @Operation(summary = "删除视频")
    @Log(value = "视频管理-删除视频", persist = true)
    public AjaxResult delete(@RequestParam Integer id) throws Exception {
        return videoService.delete(id);
    }

    @PutMapping("/update")
    @Operation(summary = "更新视频")
    @Log(value = "视频管理-更新视频", persist = true)
    public AjaxResult update(@RequestBody Videos videos) {
        return videoService.update(videos);
    }

    @GetMapping("/info")
    @Operation(summary = "视频信息")
    @Log(value = "视频管理-视频信息", persist = true)
    public AjaxResult info(@RequestParam Integer id) throws Exception {
        return videoService.info(id);
    }

    @PostMapping("/cover")
    @Operation(summary = "上传视频封面文件")
    @Log(value = "视频管理-上传视频封面文件", persist = true)
    public AjaxResult cover(@RequestParam MultipartFile file, @RequestParam Integer id) throws Exception {
        return videoService.cover(file, id);
    }

    @GetMapping("/parts")
    @Operation(summary = "分集列表")
    @Log(value = "视频管理-分集列表", persist = true)
    public AjaxResult parts(@RequestParam Integer id) throws Exception {
        return videoService.parts(id);
    }

    @DeleteMapping("/part/delete")
    @Operation(summary = "删除剧集")
    @Log(value = "视频管理-删除剧集", persist = true)
    public AjaxResult deletePart(@RequestParam Integer id) throws Exception {
        return videoService.deletePart(id);
    }

    @PostMapping("/part/add")
    @Operation(summary = "添加剧集")
    @Log(value = "视频管理-添加剧集", persist = true)
    public AjaxResult addPart(@RequestBody VideoParts videoParts) throws Exception {
        return videoService.addPart(videoParts);
    }

    @GetMapping("/part/file/list")
    @Operation(summary = "剧集文件列表")
    @Log("视频管理-剧集文件列表")
    public AjaxResult partFiles(@RequestParam Integer id) throws Exception {
        return videoService.partFiles(id);
    }

    @DeleteMapping("/part/file/delete")
    @Operation(summary = "删除剧集文件")
    @Log(value = "视频管理-删除剧集文件", persist = true)
    public AjaxResult partDeleteFile(@RequestParam Integer id, @RequestParam String filename) throws Exception {
        return videoService.partDeleteFile(id, filename);
    }

    @DeleteMapping("/part/file/clear")
    @Operation(summary = "清空剧集文件")
    @Log(value = "视频管理-清空剧集文件", persist = true)
    public AjaxResult partClearFile(@RequestParam Integer id) throws Exception {
        return videoService.partClearFile(id);
    }

    @PostMapping("/part/file/upload")
    @Operation(summary = "上传剧集文件")
    @Log(value = "视频管理-上传剧集文件", persist = true)
    public AjaxResult partUploadFile(@RequestParam MultipartFile file, @RequestParam Integer id) throws Exception {
        return videoService.partUploadFile(file, id);
    }
}
